/*   Shotscreens
 *   Copyright (C) 2010, Vadim Zakondyrin (http://crystalnix.com)
 *
 *   This program is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "qgraphicstextrectitem.h"
#include <QPen>

QGraphicsTextRectItem::QGraphicsTextRectItem(QGraphicsItem * parent)
    : QGraphicsItemGroup(parent)
{
    initialization();
}

QGraphicsTextRectItem::QGraphicsTextRectItem(const QString & text, QGraphicsItem * parent)
    : QGraphicsItemGroup(parent)
{
    initialization();
    p_textItem->setPlainText(text);
}

QGraphicsTextRectItem::~QGraphicsTextRectItem()
{

}


void QGraphicsTextRectItem::initialization()
{
    p_rectItem = new QGraphicsRectItem(this);

    p_rectItem->setBrush(QBrush(QColor(0,0,0,0)));
    p_rectItem->setPen(QPen(QBrush(Qt::black),0));

    p_textItem = new QGraphicsTextItem(this);


}
void QGraphicsTextRectItem::SetPen(QPen b,int w)
{
    b.setWidth(w);

    p_rectItem->setPen(b);

}

void QGraphicsTextRectItem::setRect(const QPointF &firstPoint, const QPointF &secondPoint)
{
    QRectF rect;

    if (firstPoint.x() < secondPoint.x()) {
        rect.setX(firstPoint.x());
        rect.setWidth(secondPoint.x() - firstPoint.x());
    } else {
        rect.setX(secondPoint.x());
        rect.setWidth(firstPoint.x() - secondPoint.x());
    }

    if (firstPoint.y() < secondPoint.y()) {
        rect.setY(firstPoint.y());
        rect.setHeight(secondPoint.y() - firstPoint.y());
    } else {
        rect.setY(secondPoint.y());
        rect.setHeight(firstPoint.y() - secondPoint.y());
    }

    p_rectItem->setRect(rect);





}
